package com.mz361.component.payment.config.properties;

import com.alipay.easysdk.factory.Factory;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.h5.H5Service;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import com.wechat.pay.java.service.refund.RefundService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * jwt配置项
 *
 * @author niceale * @date 2019/4/13
 */
@Configuration
@Slf4j
@Data
public class PayMentProjectProperties {


    /**
     * 商户号
     */
    @Value("${project.wx.merchantId}")
    public String merchantId;


    /**
     * 小程序APPID
     */
    @Value("${project.wx.miniappId}")
    public String miniappId;

    @Value("${project.aliyun.returnUrl}")
    public String returnUrl;

    /**
     * 微信公众号APPID
     */
    public final static String appId = "wxeba6ed26e87c25bb";

    /**
     * 微信公众号密码
     */
    public final static String appSecret = "aa9e22ce376cad0e0f4986cb18d7615f";

    /**
     * 商户API私钥路径
     */
    @Value("${project.wx.privateKeyPath}")
    public String privateKeyPath;

    /**
     * 商户证书序列号
     */
    public final static String merchantSerialNumber = "3FD5BA6C3D11FC6875CCAD6289258DC32E069EAE";

    /**
     * 商户APIV3密钥
     */
    public final static String apiV3Key = "3C9406E182E68ACE48E02302DA87F352";


    /* *//*支付宝支付*/
    public final static String aliappId = "2021004160630973";
    /**
     * 支付宝商户API私钥
     */
    public final static String merchantPrivateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCJuM/ktuRc1t3tCerVp3LjRU32MKRr2DJz7TP4oJ9MJWAo3afu9leK8WH2s+DYzgCNjTyQZBtOHjSj8CvADvhWrO1z3dkyoor+Hbe4KOIHWYdYS0Fz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OiVmu7d5RFSgmQZAhAoGAV4LvAdFrkaej2QEvPhFOeh1p3rr8HJNPZz0n9gKSVes8RkZ60ETj7NJEGH6Ou5wG1xBkeLclHcvNDvx/OvE9a9oW4RMjCsJzkDEFo0gWpFnwEPgmZYOc+DkAE/ro1vfHR/ruIP3uAB98G/+T9BTq7fAVLR6BPes0uLQ/hLKePz0CgYBlIgvB1hxM5o3OCx6WQx9voGwXQSlGrqc2DaXFJUtdjZoqrKvKvLclWuhLHhElvOIQjEFFaDutFC9ZLNlC3Qf7VGEvQCt69mG7lvvMs838Q97zCHPE+IRbp0+bEzK27IglgKQf6yW4mTPH7tmA9qwlcwZv3S5L0NxC0f4nz3h19Q==";
    /**
     * 支付宝公钥证书文件路径路
     */
    public final static String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNKWcmRn+A48ruV3RH3bYwWr1qJmexLgiux4gKDms8QAGbFvhgAkr0SNIlQGJdFqVcyQD8mXWI31w92bqLWPKS6mODIP6VDYLtNm+odWPGbLZWDCe37519mP37Z+i2Hh7rgNPSlDjPnzsMX+ns4JMU5MPoo6uXzS+82WmG6Z66t9qVQJaS9Tsys7C/RFCe49BVORJSSv4KLT7tgIL+eo8auCbfL9NvOoHJ34/aHvEsRWySdY5lspXbO9dCFVQbiNWDzIakRVpYQnN/Ek6f2ZjlX2Tfc6PyTtboaWKb+P/iTVVq32qHUBWkslVMRFOOIwfQumOJXGn2ALRfz9LFXsmwIDAQAB";

    /**
     * 支付宝支付类接口异步通知接收服务地址
     */
    @Value("${project.wx.notifyUrl}")
    public String notifyUrl;


    /**
     * 支付宝AES密钥
     */
    public final static String encryptKey = "QluCM4uW36eHtEb4y8Qhxg==";

    /**
     * 微信配置信息
     *
     * @return
     */
    public Config config() {
        return new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3Key)
                .build();
    }

    /**
     * 付款
     *
     * @return
     */
    @Bean
    public NativePayService nativePayService() {

        return new NativePayService.Builder().config(config()).build();
    }

    @Bean
    public H5Service h5Service() {
        return new H5Service.Builder().config(config()).build();
    }

    @Bean
    public JsapiService jsapiService() {
        return new JsapiService.Builder().config(config()).build();
    }

    @Bean
    public JsapiServiceExtension jsapiExtensionService() {
        return new JsapiServiceExtension.Builder().config(config()).build();
    }

    /**
     * 退款
     *
     * @return
     */
    @Bean
    public RefundService refundService() {
        return new RefundService.Builder().config(config()).build();
    }

    /**
     * 微信分账
     *
     * @return
     */
    @Bean
    public ProfitsharingService profitsharingService() {
        return new ProfitsharingService.Builder().config(config()).build();
    }

    @Bean
    public com.alipay.easysdk.kernel.Config getOptions() {
        com.alipay.easysdk.kernel.Config config = new com.alipay.easysdk.kernel.Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipay.com";
        config.signType = "RSA2";
        config.appId = aliappId;
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = merchantPrivateKey;
        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        config.alipayPublicKey = alipayPublicKey;
        //可设置异步通知接收服务地址（可选）
        config.notifyUrl = notifyUrl;
        //可设置AES密钥，调用AES加解密相关接口时需要（可选）
        config.encryptKey = encryptKey;
        Factory.setOptions(config);
        return config;
    }


}
